#Include <..\include\Common_For_PageManager.au3>
#Include <GuiButton.au3>


AutoItSetOption("MustDeclareVars", 1)   ;Variables must be pre-declared.
Global $hPMHandle, $sCusMsg, $sFailLogMsg
Dim Const $sFunctionFolderName = "Find"  
Global Const $sExcelSheetName = 'Find'
Dim Const $sCorrectResultPath = "C:\Find\Correct Resut\"  
Dim Const $sTestResultPath = "C:\Find\Perform Result\"  
Dim Const $sSampleFolderPath = "C:\Find\Sample\" 
Dim Const $iNumber = Common_GetNumberInExcelSheet($oExcel,$sExcelSheetName)  
Dim Const $iCurrentSheetTotalLineNumber = $iNumber[0]   ;Get all number of rows in current excel sheet.
Dim Const $sFunctionFolderPath = "C:\Find\"  
Dim Const $CommonWindowCtrlInfro = ''
Dim Const $sLogFileName =  "Find.Log"   ;Log file named(Same with .au3 file name).
Dim Const $sMenuIdentify = "[Class:#32768]"
Dim Const $sAlertmessage_EmptySearch = "Presto! PageManager"

Dim Const $iPageviewInPagemanagerCtrInfo = 59649
Dim Const $sFindDialogTitle = "Search File"
Dim Const $sIndexSearchAlert = "Search Tips"

Global Const $iRescolumn = 14

Dim Const $sEditMenuHotKey = ReadIniKeyValue($sPCodeIniPath, $sSectionNameThumbanil, 'EditMenuHotKey')
Dim Const $sToolsMenuHotKey = ReadIniKeyValue($sPCodeIniPath, $sSectionNameThumbanil, 'ToolsMenu')
Dim Const $sViewMenuHotKey = ReadIniKeyValue($sPCodeIniPath, $sSectionNameThumbanil, 'ViewMenuHotKey')
Dim Const $sFileMenuHotKey = ReadIniKeyValue($sPCodeIniPath, $sSectionNameThumbanil, 'FileMenuHotKey')
Dim Const $sAnnotationBarCtrlInfo = ReadIniKeyValue($sPCodeIniPath, $sSectionNameThumbanil, 'AnnotationBar')

Func SelectSearchResult($iOrder)
	Local $h = ControlGetHandle($sFindDialogTitle, "", 4032)
	If $h = "" Then
		Return False
	Else
		_GUICtrlListView_ClickItem($h , $iOrder)
		Common_SleepTime(1)	
		Return True
	EndIf
EndFunc

Func InitializeStatusForFind()
	$hPMHandle = ""
	Local $FileList = _FileListToArray ($sFunctionFolderPath,"*", 1)
	If Not @error Then
		If $FileList[0] >= 1 Then
			For $i = 1 to $FileList[0]
				FileDelete ($sFunctionFolderPath & $FileList[$i])
			Next
			Return 1
		EndIf
	EndIf
	ClipPut("")
EndFunc

Func ClickGotoButton()
	If ControlClick($sFindDialogTitle, '',4005) Then
		Return True
		Common_SleepTime(8)
	Else
		Return False
	EndIf
EndFunc

Func SetSearchPath($sPath)
	if  ControlFocus($sFindDialogTitle, '', 1001) Then
		For $i = 0 to 30
			Send("{DEL}")
		Next
	EndIf
	if ControlSend($sFindDialogTitle, '', 1001, $sPath) Then
		Return True
	Else
		Return False
	EndIf
EndFunc

Func CheckonBookmark()
	ControlClick($sFindDialogTitle, "", 4026)
	Sleep(300)
EndFunc

Func Checkonhighlight()
	ControlClick($sFindDialogTitle, "", 4027)
	Sleep(300)
EndFunc

Func AddBookmarkHighliht()
	; Add bookmark and highliht.
	If $bPageViewType = 1 Then
		MouseClick("left",1108,285)
		Common_SleepTime(1)
	Else
		MouseClick("left",999,144)
		Common_SleepTime(1)
		MouseMove(368, 241)
		MouseDown("left")
		Common_SleepTime(1)
		MouseMove(647, 391)
		MouseUp("left")
		Common_SleepTime(1)
		MouseClick("left",1000,231)
		Common_SleepTime(1)		
		MouseClick("left",998,268)
		Common_SleepTime(1)	
	EndIf
EndFunc

Func OpenMenu($sMenu)
	Switch $sMenu
	Case "Edit"
		Send("!" & $sEditMenuHotKey)	
		Sleep(300)
	Case "Tools"
		Send("!" & $sToolsMenuHotKey)	
		Sleep(300)	
	Case "View"
		Send("!" & $sViewMenuHotKey)	
		Sleep(300)
	Case "File"
		Send("!" & $sFileMenuHotKey)	
		Sleep(300)
	EndSwitch	
EndFunc

Func OpenFindDialog()
	OpenMenu("Edit")
	Sleep(300)
	Send("f")
	If WinWaitActive($sFindDialogTitle, "", 8) Then
		Sleep(300)
		WinActivate($sFindDialogTitle)
		Return True
	Else
		Return False
	EndIf
EndFunc

Func ClickSearchButton($hFindDialog)
	ControlClick($hFindDialog, "", 4003)
	Common_SleepTime(4)
EndFunc

Func CheckonIndexSearch()
	If _GUICtrlButton_GetState(ControlGetHandle($sFindDialogTitle,'',4042)) = 0 Then
		ControlClick($sFindDialogTitle, "", 4042)
		Common_SleepTime(1)
	EndIf	
EndFunc	

Func CheckonCaseSensitive($hFindDialog)
	If _GUICtrlButton_GetState(ControlGetHandle($hFindDialog,'',4025)) = 0 Then
		ControlClick($hFindDialog, "", 4025)
		Sleep(100)
	EndIf	
EndFunc

Func SetLocateTextOfSearch($hFindDialog,$sText)
	ControlFocus($hFindDialog, "", 4002)
	ControlSend($hFindDialog, "", 4002, $sText)
	Sleep(200)
EndFunc

Func CloseFindDialog($hFindDialog)
	WinActivate($hFindDialog)
	ControlClick($hFindDialog, "", 2)
EndFunc

Func SelectFindOptions($item)
	Switch $item
	Case "Author"
		If _GUICtrlButton_GetState(ControlGetHandle($sFindDialogTitle,'',4043)) = 0 Then
			ControlClick($sFindDialogTitle, "", 4043)
			Sleep(100)
		EndIf
	Case "Annotations"
		If _GUICtrlButton_GetState(ControlGetHandle($sFindDialogTitle,'',4024)) = 0 Then
			ControlClick($sFindDialogTitle, "", 4024)
			Sleep(100)
		EndIf	
	Case "Keywords"
		If _GUICtrlButton_GetState(ControlGetHandle($sFindDialogTitle,'',4022)) = 0 Then
			ControlClick($sFindDialogTitle, "", 4022)
			Sleep(100)
		EndIf		
	Case "Memo"
		If _GUICtrlButton_GetState(ControlGetHandle($sFindDialogTitle,'',4023)) = 0 Then
			ControlClick($sFindDialogTitle, "",4023)
			Sleep(100)
		EndIf		
	Case "OCR results"
		If _GUICtrlButton_GetState(ControlGetHandle($sFindDialogTitle,'',4040)) = 0 Then
			ControlClick($sFindDialogTitle, "", 4040)
			Sleep(100)
		EndIf
	Case "Contents"
		If _GUICtrlButton_GetState(ControlGetHandle($sFindDialogTitle,'',4021)) = 0 Then
			ControlClick($sFindDialogTitle, "", 4021)
			Sleep(100)
		EndIf
	EndSwitch	
EndFunc











